﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Management;
using System.Text;
using WMI.NET.Abstracts;
using WMI.NET.CIM;

namespace WMI.NET.ComputerSystemHardware.MotherboardControllerPort
{
    /// <summary>
    /// The Win32_AllocatedResource association WMI class relates a logical device to a system resource. This class is used to discover which resources, such as IRQs or DMA channels, are in use by a specific device.
    /// This class is obsolete. In place of this class, you should use the properties in the Win32_PNPAllocatedResource class.
    /// </summary>
    public class Win32_AllocatedResource : CIM_Dependency
    {

        private CIM_SystemResource _Antecedent;
        private CIM_LogicalDevice _Dependent;

        /// <summary>
        /// Reference to the CIM_SystemResource instance representing the properties of a system resource available to the logical device. This property is inherited from CIM_Dependency.
        /// </summary>
        new public CIM_SystemResource Antecedent { get { return _Antecedent; } }

        /// <summary>
        /// Reference to the CIM_LogicalDevice instance representing the properties of the logical device that is using the system resources assigned to it. This property is inherited from CIM_Dependency.
        /// </summary>
        new public CIM_LogicalDevice Dependent { get { return _Dependent; } }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="mbo"></param>
        public Win32_AllocatedResource(ManagementBaseObject mbo)
            : base(null)
        {
            _Antecedent = mbo.GetSubWin32Class("Antecedent");
            _Dependent = mbo.GetSubWin32Class("Dependent");
        }


    }

    /// <summary>
    /// 
    /// </summary>
    public class GetWin32_AllocatedResources : Win32Collection<Win32_AllocatedResource>
    {

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ReadOnlyCollection<Win32_AllocatedResource> GetCollection()
        {
            List<Win32_AllocatedResource> tempCollection = new List<Win32_AllocatedResource>();

            foreach (var s in searcher.Get())
            {

                Win32_AllocatedResource tempListItem = new Win32_AllocatedResource(s);
                tempCollection.Add(tempListItem);
            }

            return tempCollection.AsReadOnly();
        }

        /// <summary>
        /// 
        /// </summary>
        public GetWin32_AllocatedResources() : base("SELECT * FROM Win32_AllocatedResource") { }

    }

}

